#include <iostream>
#include <vector>
using namespace std;

class TPoint {
public:
	int x,y;
	TPoint(void) {x=y=0;}
	TPoint(int x, int y) {this->x=x; this->y=y;}
	TPoint& operator= (const TPoint& p) {
		x = p.x;
		y = p.y;
		return *this;
	}
};

vector<TPoint> plist;

char map[400][400];

void fold(void) {
	vector<TPoint> incList;
	TPoint o = plist[plist.size()-1];
	for (int i=plist.size()-2; i>=0; --i) {
		TPoint v;
		TPoint cur = plist[i];
		v.x = cur.x - o.x;
		v.y = cur.y - o.y;

		incList.push_back(TPoint(0*v.x+1*v.y+o.x, -1*v.x+0*v.y+o.y));
	}
	for (unsigned int i=0; i<incList.size(); ++i) {
		plist.push_back(incList[i]);
	}
}

int cx=200,cy=200;

int main(void)
{
	int n;
	while (true) {
		cin >> n;
		if (n == 0) break;
		plist.clear();
		plist.push_back(TPoint(0,0));
		plist.push_back(TPoint(1,0));

		for (int i=0; i<n; ++i)
			fold();

		int maxX, minX, maxY, minY;
		maxX = maxY = -1000;
		minX = minY = 1000;

		for (int i=0; i<400; ++i)
			for (int j=0; j<400; ++j)
				map[i][j] = ' ';

// 		cout << plist.size() << endl;
// 		for (int i=0; i<plist.size(); ++i)
// 			cout << plist[i].x << " " << plist[i].y << endl;
		for (unsigned int i=0; i<plist.size()-1; ++i) {
			TPoint a = plist[i];
			TPoint b = plist[i+1];
			TPoint tar;
			if (a.y == b.y) {
				if (b.x > a.x) {
					tar = a;
				}
				else {
					tar = b;
				}

				map[cx+2*tar.x][cy+tar.y] = '_';
				maxX = max(maxX, 2*tar.x);
				minX = min(minX, 2*tar.x);
				maxY = max(maxY, tar.y);
				minY = min(minY, tar.y);
			}
			if (a.x == b.x) {
				if (b.y > a.y) {
					tar = a;
				}
				else {
					tar = b;
				}
				map[cx+2*tar.x-1][cy+tar.y] = '|';
				maxX = max(maxX, 2*tar.x-1);
				minX = min(minX, 2*tar.x-1);
				maxY = max(maxY, tar.y);
				minY = min(minY, tar.y);
			}
// 			cout << tar.x << " " << tar.y << endl;
// 
// 			for (int i=505; i>=495; --i) {
// 				for (int j=495; j<=505; ++j)
// 					cout << map[j][i];
// 				cout << endl;
// 			}

		}
		for (int i=cy+maxY; i>=cy+minY; --i) {
			int b;
			for (int j=cx+maxX; j>0; --j)
				if (map[j][i] != ' ') {
					b = j;
					break;
				}
			for (int j=cx+minX; j<=b; ++j)
				cout << map[j][i];
			cout << endl;
		}
		cout << '^' << endl;
	}

	return 0;
}